
import 'dart:async';
import '../utils/ApiService.dart';
import 'definitions/ResultModel.dart';
import 'definitions/UserModel.dart';
import 'definitions/ResultUserModel.dart';


class UserController {

    static String updateUsingPutPath = "/api/user/update";
    /// 1. 修改用户个人信息
    static Future<ResultModel> updateUsingPut(UserModel data,[ dynamic headers ]) async {
      var response = await ApiService.put("/api/user/update", data.toJson() , headers);
      return ResultModel()..fromJson(response.data);
    }
    
    static String logoutUsingPostPath = "/api/user/logout";
    /// 2. 退出
    static Future<ResultUserModel> logoutUsingPost([ dynamic headers ]) async {
      var response = await ApiService.post("/api/user/logout", null, headers);
      return ResultUserModel()..fromJson(response.data);
    }
    
    static String currentUsingGetPath = "/api/user/current";
    /// 3. 获取个人信息
    static Future<ResultUserModel> currentUsingGet([dynamic headers]) async {
      var response = await ApiService.get("/api/user/current", {}, headers);
      return ResultUserModel()..fromJson(response.data);
    }
    
    static String registerUsingPostPath = "/api/user/register";
    /// 4. 注册用户信息
    static Future<ResultUserModel> registerUsingPost(UserModel data,[ dynamic headers ]) async {
      var response = await ApiService.post("/api/user/register", data.toJson() , headers);
      return ResultUserModel()..fromJson(response.data);
    }
    
    static String userInfoUsingGetPath = "/api/user/userInfo/{id}";
    /// 5. 根据ID获取用户信息
    static Future<ResultUserModel> userInfoUsingGet(String id, [dynamic headers]) async {
      var response = await ApiService.get("/api/user/userInfo/$id", {}, headers);
      return ResultUserModel()..fromJson(response.data);
    }
    
}